<!DOCTYPE html>
<html class="x-admin-sm">

<head>
    <meta charset="UTF-8">
    <title>用户信息编辑</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
        content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
    <link rel="stylesheet" href="/web/res/css/xadmin.css">
    <script src="/web/res/lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="/web/res/js/xadmin.js"></script>
</head>

<body style="background-color: white;">
    <div class="layui-fluid" id="orderEdit">
        <form class="layui-form layui-form-pane" id="formsubmit" style="width: 500px;margin:20px auto" action="">

            <input type="hidden" name="id" value="${(user.id?c)!''}"/>
            <fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
                <legend class="form-title">用户信息</legend>
            </fieldset>

            <div class="layui-form-item" >
                <div class="layui-upload">
                    <label class="layui-form-label">用户头像</label>

                    <div class="layui-upload">
                        <div class="upload-list">
                            <#if user?exists && user.touxiang?exists>
                            <div class="upload-imgBox">
                                <input type="hidden"  id="imgpathhide" value="${(user.touxiang)!''}"  class="layui-input"/>
                                <img  src="${(user.touxiang)!''}" class="upload-select-img">
                            </div>
                            <#else>
                            </#if>
                        </div>
                    </div>
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">用户昵称</label>
                <div class="layui-input-block">
                    <input type="text"  class="layui-input" placeholder="${(user.nicheng)!''}" readonly/>
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">用户性别</label>
                <div class="layui-input-block">
                    <input type="text"  class="layui-input" placeholder="<@mapIntString map=sexMap key=user.sex/>" readonly/>
                </div>
            </div>

           <div class="layui-form-item">
               <label class="layui-form-label">用户手机号</label>
               <div class="layui-input-block">
                   <input type="text"  class="layui-input" placeholder="${(user.userphone)!''}" readonly/>
               </div>
           </div>

           <div class="layui-form-item">
               <label class="layui-form-label">用户账号</label>
               <div class="layui-input-block">
                   <input type="text"  class="layui-input" placeholder="${(user.zhanghao)!''}" readonly/>
               </div>
           </div>

    <div class="layui-form-item">
        <label class="layui-form-label">用户状态</label>
        <div class="layui-input-block">
            <input type="text"  placeholder="  <@mapIntString map=stateMap key=user.state/>" autocomplete="off" class="layui-input" readonly/>
        </div>
    </div>



            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button type="button" class="layui-btn layui-btn-primary layui-btn-radius" onclick="xadmin.close()">&emsp;返回&emsp;</button>
                </div>
            </div>
        </form>
    </div>
    <script>
        layui.use(['form', 'upload'], function () {
            let $ = layui.$;
            var form = layui.form;
            var upload = layui.upload;
            form.render();

            $.fn.extend({
                serializeObject: function() {
                    var obj = {}; //声明一个对象
                    $.each(this.serializeArray(), function(index, field) {
                        obj[field.name] = field.value; //通过变量，将属性值，属性一起放到对象中
                    })
                    return obj;
                }
            });

            // 重新添加删除功能
            $('.upload-cancel').on('click', (event) => {
                let self = $(event.currentTarget);
                self.parent().remove();
                event.stopPropagation();

                if($("input[id='imgpathhide']").length<1){
                    $('#uploadtemplate').show();
                }else{
                    $('#uploadtemplate').hide();
                }
            });

            upload.render({
                elem: '#uploadtemplate',
                auto: false,
                accept: 'images',
                acceptMime: 'image/*',
                choose: function (obj) {
                    obj.preview(function (index, file, result) {
                        $('#uploadlist').prepend('<div class="upload-imgBox">  <input type="hidden"  id="imgpathhide" value="'+result+'"  class="layui-input"/><div class="upload-cancel" id="'+index+'">x</div><img  src="' + result + '" alt="' + file.name +
                            '" class="upload-select-img"></div>');
                        $(".upload-cancel").on("click",function(e){
                            $(this).parent().remove();
                            if($("input[id='imgpathhide']").length<1){
                                $('#uploadtemplate').show();
                            }
                        })
                        if($("input[id='imgpathhide']").length>=1){
                            $('#uploadtemplate').hide();
                        }
                        // alert($("input[id='imgpathhide']").length);
                    });
                },
                done: function (res) {
                }
            });


            form.on('submit('+$("button[lay-submit]:eq(0)").attr("lay-filter")+')', function(data){
                $("input[id='imgpathhide']").each(function(index,ele){
                    // $(this).attr("name","imgList["+index+"]");
                    $(this).attr("name","headpic");
                });

                layer.confirm('确认要进行操作吗？', function (index) {
                    ajaxPost($,$("#formsubmit").attr("action"),$("#formsubmit").serializeObject(),function (data) {
                        if (data.code == 0) {
                            layer.msg(data.msg, {icon: 1, time: 1000}, function(){
                                xadmin.father_reload();
                            });
                        } else {
                            layer.msg(data.msg, {icon: 2, time: 3000}, function(){
                            });
                        }
                    });
                });
            });
        });
    </script>

    <script>
        //通过
        function tongGuo(obj, id) {
            layui.use('layer',function () {
                let $ = layui.$;
                layer.confirm('确认要启用该账号吗？', function (index) {
                    ajaxPost($,"/customer/tongGuo",{"id":id},function (data) {
                        if (data.code == 0) {
                            layer.msg(data.msg, {icon: 1, time: 1000}, function(){
                                xadmin.father_reload();
                            });
                        } else {
                            layer.msg(data.msg, {icon: 2, time: 1000}, function(){
                            });
                        }
                    });
                });
            });
        }

        //拒绝
        function juJue(obj, id) {
            layui.use('layer',function () {
                let $ = layui.$;
                layer.confirm('确认要封禁该账号吗？', function (index) {
                    ajaxPost($,"/customer/juJue",{"id":id},function (data) {
                        if (data.code == 0) {
                            layer.msg(data.msg, {icon: 1, time: 1000}, function(){
                                xadmin.father_reload();
                            });
                        } else {
                            layer.msg(data.msg, {icon: 2, time: 1000}, function(){
                            });
                        }
                    });
                });
            });
        }

    </script>


</body>

</html>